package com.easy.controller;


import com.easy.bean.Staff;
import com.easy.service.StaffService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin//允许跨域访问
@RequestMapping("staff")
public class StaffController {
    @Autowired
    StaffService staffService;

    @PostMapping
    public Result add(@RequestBody Staff staff) {
        Object obj = staffService.add(staff);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Staff staff) {
        Object obj = staffService.edit(staff);
        return Result.success(obj);
    }



    @DeleteMapping("{id}")
    public Result del(@PathVariable(name = "id") Integer id) {
        Object obj = staffService.del(id);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj = staffService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Staff staff) {
        Object obj = staffService.all(staff);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, Staff staff) {
        staffService.page(page, staff);
        return Result.success(page);
    }
}